<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="/WEB-INF/tlds/messageTag.tld" prefix="msg"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title><msg:message key="menu.user" /></title>

	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="renderer" content="webkit">
	<meta name="description" content="客户管理">
	<!-- <meta name="viewport" content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0"> -->
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/ztree/demo.css" type="text/css">
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/base.css">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
	
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/bootstrap.min.css" />
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/style.css" />
	
	<link rel="stylesheet" href="${pageContext.request.contextPath}/css/upload/uploadfile.css" />
	
	<!-- 底部加载js -->
	<script src="${pageContext.request.contextPath}/js/jquery-1.12.4.min.js"></script>
	<!-- 底部加载js -->
	<!-- bootstrap 引入 -->
	<script src="${pageContext.request.contextPath}/js/tether.min.js"></script>
	<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
	<!-- 引入弹窗 layer -->
	<script src="${pageContext.request.contextPath}/js/layer/layer.js"></script>
	<script src="${pageContext.request.contextPath}/js/page/common.js"></script>
	
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/ztree/jquery.ztree.core.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath}/js/ztree/jquery.ztree.excheck.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/js/upload/ajaxfileuploadfile.js"></script>
	
	<script type="text/javascript">
	function firmwareMgr() {
		location.href = "${pageContext.request.contextPath}/showFirmwareList.do";
	}
	
	var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};

		var zNodes = eval(${jsontree});
		
		function getMenuIds() {
				var zTree = $.fn.zTree.getZTreeObj("treeDemo");  
				var nodes=zTree.getCheckedNodes(true);  
				var result='';  
				if(nodes.length==0){  
					alert("请选择路灯！");  
					return false;  
				}  
				for (var i = 0; i < nodes.length; i++) {  
					//var halfCheck = nodes[i].getCheckStatus();  
					//if (!halfCheck.half && !nodes[i].isParent){  
						result += nodes[i].id +',';  
					//}  
				}  
				result=result.substring(0,result.lastIndexOf(","));
				return result;
		}
	</script>
  </head>
  
  <body>
  	<div class="header">
		<div class="left header-logo"><img class="header-logo-img" src="images/header_logo.png" /></div>
		<div class="right header-nav">
			<a class="nav-link" href="${pageContext.request.contextPath }/main.do">
				<i class="icon icon-home"></i>
				<span class="link-text"><msg:message key="menu.homepage" /></span>
			</a>
			<c:if test="${menubean.menu1 }">
			<a class="nav-link" href="${pageContext.request.contextPath }/showDevice.do">
				<i class="icon icon-install"></i>
				<span class="link-text"><msg:message key="menu.install" /></span>
			</a>
			</c:if>
			<c:if test="${menubean.menu2 }">
			<a class="nav-link" href="${pageContext.request.contextPath}/showConfig.do">
				<i class="icon icon-config"></i>
				<span class="link-text"><msg:message key="menu.config" /></span>
			</a>
			</c:if>
			<c:if test="${menubean.menu3 }">
			<!-- <a class="nav-link" href="operation.html">
				<i class="icon icon-operation"></i>
				<span class="link-text">操作</span>
			</a> -->
			<a class="nav-link" href="${pageContext.request.contextPath}/dataNew.do">
				<i class="icon icon-data"></i>
				<span class="link-text"><msg:message key="menu.data" /></span>
			</a>
			</c:if>
			<%-- <c:if test="${menubean.menu4 }">
			<a class="nav-link" href="history.html">
				<i class="icon icon-history"></i>
				<span class="link-text">历史</span>
			</a>
			</c:if> --%>
			<c:if test="${menubean.menu4 }">
			<a class="nav-link" href="${pageContext.request.contextPath}/faultList.do">
				<i class="icon icon-malfunction"></i>
				<span class="link-text"><msg:message key="menu.error" /></span>
			</a>
			</c:if>
			<c:if test="${menubean.menu5 }">
			<a class="nav-link" href="${pageContext.request.contextPath}/showUserList.do">
				<i class="icon icon-customer-management"></i>
				<span class="link-text"><msg:message key="menu.user" /></span>
			</a>
			</c:if>
			<c:if test="${menubean.menu6 }">
			<a class="nav-link" href="${pageContext.request.contextPath}/statusList.do">
				<i class="icon icon-status"></i>
				<span class="link-text"><msg:message key="menu.status" /></span>
			</a>
			</c:if>
			<c:if test="${menubean.menu7 }">
			<a class="nav-link" href="${pageContext.request.contextPath}/currentList.do">
				<i class="icon icon-malfunction"></i>
				<span class="link-text"><msg:message key="menu.current" /></span>
			</a>
			</c:if>
			<c:if test="${menubean.menu8 }">
			<a class="nav-link" href="${pageContext.request.contextPath}/report.do">
				<i class="icon icon-history"></i>
				<span class="link-text"><msg:message key="menu.report" /></span>
			</a>
			</c:if>
			<c:if test="${menubean.menu9 }">
			<a class="nav-link active" href="${pageContext.request.contextPath}/showFirmwareList.do">
				<i class="icon icon-config"></i>
				<span class="link-text"><msg:message key="menu.upfirmware" /></span>
			</a>
			</c:if>
			<a class="nav-link" href="${pageContext.request.contextPath}/logout.do">
				<i class="icon icon-out"></i>
				<span class="link-text"><msg:message key="menu.exit" /></span>
			</a>
			<div class="clear"></div>
		</div>
		<div class="clear"></div>
	</div>
  	
  	<div class="block20"></div>
	<div class="page-mainbox">

		<div>
			<button class="btn btn-warning" id="upFirmwareBtn">定向升级</button>
			<button class="btn btn-primary" onclick="firmwareMgr()"><msg:message key="firmware.btn.mgr" /></button>
		</div>
		<div class="block20"></div>

		<table class="table table-striped table-hover  bg-white">
			<thead>
				<tr>
					<th style="text-align: left;padding-left:15px;">项目编号</th>
					<th style="text-align: left;padding-left:15px;">设备编号</th>
					<th style="text-align: left;padding-left:15px;">固件版本</th>
					<th style="text-align: left;padding-left:15px;"><msg:message key="firmware.operation" /></th>
				</tr>
			</thead>
			<tbody>
			<c:forEach items="${lightFirmwareList }" var="lightFirmware">
				<tr>
					<td>${lightFirmware.panId }</td>
					<td>${lightFirmware.lightNum }</td>
					<td>${lightFirmware.firmwareVersion }</td>
					<td>
						<div class="td-oper-div">
							<%-- <button class="btn btn-danger" name="firmwareDelBtn" data-id="${firmware.id }"><msg:message key="user.btn.delete" /></button> --%>
						</div>
					</td>
				</tr>
			</c:forEach>
			</tbody>
		</table>
	</div>
	
	<div class="block20"></div>

	<!-- <div>
		<nav aria-label="Page navigation example">
			<ul class="pagination justify-content-center">
				<li class="page-item disabled">
				<a class="page-link" href="#" tabindex="-1">上一页</a>
				</li>
				<li class="page-item"><a class="page-link" href="#">1</a></li>
				<li class="page-item"><a class="page-link" href="#">2</a></li>
				<li class="page-item"><a class="page-link" href="#">3</a></li>
				<li class="page-item">
				<a class="page-link" href="#">下一页</a>
				</li>
			</ul>
		</nav>
	</div> -->


	<div class="hide" id="upFirmwareLayer">
		<div class="form-view padding20">
			<form id="memberForm">
			<div class="item-view item100">
				<span class="item-title"><i class="tag-must">*</i>PanId</span>
				<input type="text" class="hw_input9" id="panId" name="panId"/>
			</div>
			<div class="block10"></div>
			
			<div class="item-view item100">
				<span class="item-title"><i class="tag-must">*</i>LightNum</span>
				<input type="text" class="hw_input9" id="lightNum" name="lightNum"/>
			</div>

			<div class="block10"></div>
			
			<div class="item-view item100">
				<span class="item-title"><i class="tag-must">*</i>Version</span>
				<select id="firmwareId" name="firmwareId" class="hw_input9">
				<c:forEach items="${firmwareList}" var="firmware">
				<option value="${firmware.id}">${firmware.firmwareName }_<c:if test="${firmware.protocalVersion eq '00'}">全版本</c:if>
						<c:if test="${firmware.protocalVersion eq '01'}">自研版本</c:if>
						<c:if test="${firmware.protocalVersion eq '02'}">普天</c:if>
						<c:if test="${firmware.protocalVersion eq '03'}">远方动力</c:if>
						<c:if test="${firmware.protocalVersion eq '04'}">华慧源</c:if>
						<c:if test="${firmware.protocalVersion eq '05'}">天盈</c:if>
						<c:if test="${firmware.protocalVersion eq '06'}">硕日</c:if>_${firmware.hardwareVersion }_${firmware.firmwareVersion }</option>
				</c:forEach>
				</select>
			</div>

			<input class="hide" type="reset" name="resetBtn">
			</form>
		
		</div>
	</div>

	<script type="text/javascript">
		// 发起固件升级
		function upFirmware() {
			var panId = $("#panId").val();
			if(panId=="") {
				alert("panId不能为空！");
				return;
			}
			
			var lightNum = $("#lightNum").val();
			if(lightNum=="") {
				alert("请填写lightNum！");
				return;
			}
			
			var firmwareId = $("#firmwareId").val();
			if(firmwareId=="") {
				alert("请选择固件版本！");
				return;
			}
			
			var addFirmwareRes = false;
			
			$.ajax({
				type : "POST",
				url : "${pageContext.request.contextPath }/upFirmware.do",
				async: false,
				dataType : "json",
				data : {
					panId : panId,
					lightNum : lightNum,
					firmwareId : firmwareId
				},
				success : function(data) {
					if(data.success==0) {
						addFirmwareRes = true;
						alert(data.msg);
						layer.closeAll();
						location.href="${pageContext.request.contextPath}/lightFirmwareMgr.do";
					}else {
						alert(data.msg);
						addFirmwareRes = false;
					}
				}
			});
			
			return addFirmwareRes;
		}
		
		// 升级固件
		$('#upFirmwareBtn').click(function(){
			$('#memberForm [name="resetBtn"]').trigger('click');
			$.fn.zTree.init($("#treeDemo"), setting, zNodes);
			
			layer.open({
				type: 1,
				title: '添加固件',
				area:['700px','450px'],
				content: $('#upFirmwareLayer'),
				btn:['<msg:message key="btn.confirm" />','<msg:message key="btn.cancel" />'],
				yes:function(index){
					var res = upFirmware();
					if(res==true) {
						layer.close(index);
					}
				}
			});
		});
	</script>
  </body>
</html>
